﻿@model VisaApp.Models.VisaResModel
@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequestFromVisa"
    };
}

<script type="text/javascript">

    //    jQuery(document).ready(function () {
    //        // binds form submission and fields to the validation engine
    //        jQuery("#frm_register-visa").validationEngine('attach');
    //    });

    function completedAjaxRequestFromVisa(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        if (returnObj.Status == "success") {
            if (returnObj.Message != null) {
                makeSuccessHighlightChauLuc(returnObj.Message);
            }
            else if (returnObj.RedirectUrl != null) {
                window.location.href = returnObj.RedirectUrl;
            }

        } else {
            makeErrorHighlightFromVisa(returnObj.Message);
        }

        return false;
    }

    function makeErrorHighlightFromVisa(messageStr) {
        //        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='' style='float: left;'></span><strong>Lỗi: </strong>" + messageStr + "</p></div>");
        //        $highlight.addClass("ui-state-highlight ui-corner-all");
        //        $highlight.prependTo(".warning-area-visa");
        //        $highlight.delay(4000).fadeOut(500);
        alert(messageStr);
    }

    function makeSuccessHighlightFromVisa(messageStr) {
        var $highlight = $("<div style='padding:0.7em; margin-bottom:5px; width: inherit;'><p><span class='' style='float: left;'></span><strong>Thành công: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area-visa");
        $highlight.delay(4000).fadeOut(500);
    }

    $(document).ready(function () {

        var codes = $("#regioncode").val();
        var visadencacnuocs = $("#visadencacnuoc").val();
        $.getJSON("/Visa/AllQuocGiaByCateid/" + codes,
            function (carData) {
                var select = $("#selectProduct");
                select.empty();
                $.each(carData, function (index, itemData) {
                    if (itemData.Text == visadencacnuocs)
                        selectOn = true;
                    else
                        selectOn = false;
                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text,
                        selected: selectOn
                    }));
                });
            });

            $("#selectKhuVuc option").each(function () {
             if ($(this).val() == codes) {
                $(this).attr("selected", "selected");
                return;
            }
        });

    });


    function onSelectlistCategory() {
        var ids = $("#selectKhuVuc").val();
        $("#regioncode").val(ids);
        $.getJSON("/Visa/AllQuocGiaByCateid/" + ids,
            function (carData) {
                var select = $("#selectProduct");
                select.empty();
                $.each(carData, function (index, itemData) {
                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
                var name = carData[0].Text;
                $("#visadencacnuoc").val(name);
            });
    }

    function OnSelectProduct() {
        var txt = $("#selectProduct option:selected").text();
        $("#visadencacnuoc").val(txt);

    }

</script>
@using (Ajax.BeginForm("EdiTuVanNhanh", "Quantri", null, ajaxOpts, new { enctype = "multipart/form-data", name = "frm_register-visa", id = "frm_register-visa" }))
{
    <div class="folder-titleCenter">
        <div class="folder-activeleft fl">
        </div>
        <div class="folder-activevisa fl">
            <a class="link-foldervisa" title="Tỷ giá" href="javascript:void(0)"> </a>
        </div>
        <div class="folder-activeright fl">
        </div>
        <div class="subfolder fl">
        </div>
        <div class="folder-titleright fr">
        </div>
        <div class="fr" style="padding-top: 3px">
        </div>
    </div>
    <!-- home text -->
    <div class="folder-content">
        <div style="display: inline-block">
            <div class="box-middle1 box-weather fl">
                <div class="messageInfoSuccess">
                    <ul class="formreg">
                    <li class="warning-area-visa"></li>
                    @Html.HiddenFor(model => model.regioncode, new { id = "regioncode" })
                    @Html.HiddenFor(model => model.Id, new { id = "IdVisa" })
                    @Html.HiddenFor(model => model.DateCreate)
                    @Html.HiddenFor(model => model.Detele)
                    @Html.HiddenFor(model => model.Status)
                    @Html.HiddenFor(model => model.Type)
                     @Html.HiddenFor(model => model.visadencacnuoc, new { id = "visadencacnuoc" })
                      @Html.HiddenFor(model => model.DiaChi, new { id = "IdVisa" })
                    <li><span class="left">Khu vực</span> <span class="right">
                        <select id="selectKhuVuc" onchange = "onSelectlistCategory()">
                            <option value="142">Châu Á</option>
                            <option value="150">Châu Âu</option>
                            <option value="009">Châu Đại Dương</option>
                            <option value="002">Châu Phi</option>
                            <option value="019">Bắc Mỹ</option>
                            <option value="300">Nam Mỹ</option>
                        </select>
                    </span></li>
                    <li><span class="left">Quốc gia</span> <span class="right">
                        <select id="selectProduct" class="selectProduct" onchange="OnSelectProduct()">
                        </select>
                    </span></li>
                    <li><span class="left">Quốc tịch </span> <span class="right">
                        @Html.TextBoxFor(model => model.Quoctich, new { name = "Quoctich", value = "", @class="validate[required]", style = "width: 99%;" })
                    </span></li>
                    <li><span class="left">Họ tên <span class="namerequired">*</span></span> <span class="right">
                        @Html.TextBoxFor(model => model.HoTen, new { name = "HoTen", value = "", @class = "validate[required]", style = "width: 99%;" })
                    </span></li>
                    <li><span class="left">Email <span class="namerequired">*</span></span> <span class="right">
                        @Html.TextBoxFor(model => model.Email, new { name = "Email", value = "", @class = "validate[required,custom[email]]", style = "width: 99%;" })
                    </span></li>
                    <li><span class="left">Điện thoại <span class="namerequired">*</span></span> <span class="right">
                        @Html.TextBoxFor(model => model.Dt, new { name = "txt_pass", value = "", @class = "validate[required,custom[phone]]", style = "width: 99%;" })
                    </span></li>
                    <li class="line"><span class="left">Nội dung <span class="namerequired">*</span></span> <span class="right">
                       @Html.TextAreaFor(model => model.NoiDung, new { name = "NoiDung", @class = "txt_NoiDung validate[required]", style = "width: 98%; height:148px;" })
                    </span></li>
                    <li class="line"><span class="left">
                        <input type="submit" style="border: 0;" class="btnsubmit2" value="Đã xem và cập nhật" name=""></span>
                         <span class="right">
                        </span>
                    </li>
                </ul>
                </div>
            </div>
        </div>
    </div>
    <!-- end home text -->
    <div class="folder-bottom">
    </div>
}